<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="信息表述">
        <el-tag type="info">excel模板说明</el-tag>
        <el-tag>
          <i class="el-icon-download"/>
          <a :href="'./static/课程分类.xlsx'">点击下载模板</a>
        </el-tag>
      </el-form-item>
      <el-form-item label="选择Excel">
        <el-upload
          class="upload-demo"
          ref="upload"
          :action="BASE_API+'/eduservice/subject/addSubject'"
          :disabled="uploadDisabled"
          :on-success="fileUploadSuccess"
          :on-error="fileUploadError"
          :limit="1"
          :file-list="fileList"
          :auto-upload="false"
          accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
          <div slot="tip" class="el-upload__tip">只能上传.xlsx文件，且不超过500kb</div>
        </el-upload>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
    export default {
        name: "save",
        data() {
            return {
                fileList: [],
                uploadDisabled: false,
                BASE_API: process.env.BASE_API
            };
        },
        methods: {
            submitUpload() {
                this.uploadDisabled = true
                this.$refs.upload.submit();
            },
            fileUploadSuccess(){
                this.$message({
                    type:'success',
                    message: "导入成功"
                })
                this.$router.push("/subject/list")
            },
            fileUploadError(){
                this.$message({
                    type:'error',
                    message: "导入失败"
                })
            }
        }
    }
</script>

<style scoped>

</style>
